﻿@model MobiShop.Models.Product

@{
    ViewBag.Title = "Sửa thông tin sản phẩm";
    Layout = "~/Views/Shared/_AdminStart.cshtml";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Validate.js")" type="text/javascript"></script>

<div class="titleForm">
    <h3>Sửa thông tin sản phẩm</h3>
</div>
<div>
    <div class="boxCreateLeft"></div>
    <div class="boxtCreateCenter" style="width:800px;" >

                @using (Html.BeginForm("productEdit", "Admin", FormMethod.Post, new { enctype = "multipart/form-data" }))
                {
                    @Html.ValidationSummary(true)
                    <fieldset>
                        <legend></legend>
                        @Html.HiddenFor(model => model.id)
                        @*@Html.HiddenFor(model => model.image)*@ 
                        @* trùng name, id với thẻ input file bên dưới*@
                        <table>
                            <tr>
                                <td>@Html.LabelFor(model => model.name)</td>
                                <td>
                                    @Html.TextBoxFor(model => model.name, new { style = "width:250px;" })
                                    @Html.ValidationMessageFor(model => model.name)
                                </td>
                            </tr>
                            <tr>
                                <td>@Html.LabelFor(model => model.price)</td>
                                <td>@Html.EditorFor(model => model.price)
                                    @Html.ValidationMessageFor(model => model.price)</td>
                            </tr>
                            <tr>
                                <td>@Html.LabelFor(model => model.description)</td>
                                <td>
                                    @Html.TextAreaFor(model => model.description, new { @rows = "6", @cols = "80" })
                                    @Html.ValidationMessageFor(model => model.description)
                                </td>
                            </tr>
                            <tr>
                                <td>@Html.LabelFor(model => model.fullDescription)</td>
                                <td>
                                    @Html.TextAreaFor(model => model.fullDescription, new { @rows = "22", @cols = "80" })
                                    @Html.ValidationMessageFor(model => model.fullDescription)
                                </td>
                            </tr>
                            <tr>
                                <td>@Html.LabelFor(model => model.image)</td>
                                <td> <img src="@Url.Content("~/Content/images/" + ViewBag.imgName)" width="111" alt="" height="109" />
                                    <br /><input type='file' name='image' id='image' />
                                    <input type="checkbox" name="DeleteOldImage" id="DeleteOldImage" value="true" checked="checked" /><span id="spanDeleteOldImage" >Xóa ảnh cũ</span>
                                    </td>
                            </tr>
                            <tr>
                                <td>@Html.LabelFor(model => model.createDate)</td>
                                <td>@Html.EditorFor(model => model.createDate)
                                    @Html.ValidationMessageFor(model => model.createDate)</td>
                            </tr>
                            <tr>
                                <td>@Html.LabelFor(model => model.totalView)</td>
                                <td>@Html.EditorFor(model => model.totalView)
                                    @Html.ValidationMessageFor(model => model.totalView)</td>
                            </tr>
                            <tr>
                                <td>@Html.LabelFor(model => model.totalSale)</td>
                                <td>@Html.EditorFor(model => model.totalSale)
                                    @Html.ValidationMessageFor(model => model.totalSale)</td>
                            </tr>
                            <tr>
                                <td>@Html.LabelFor(model => model.totalQuantity)</td>
                                <td>@Html.EditorFor(model => model.totalQuantity)
                                    @Html.ValidationMessageFor(model => model.totalQuantity)</td>
                            </tr>
                            <tr>
                                <td>@Html.LabelFor(model => model.manufactureId)</td>
                                <td>@*@Html.EditorFor(model => model.manufactureId)*@
                                    @Html.DropDownList("ManufactureId", "Chọn nhà sản xuất")
@*nếu viết @Html.DropDownList("ManufactureId") thì sẽ hiển thị sai với trường hợp ManufactureId = null*@
                                    @Html.ValidationMessageFor(model => model.manufactureId)</td>
                            </tr>
                            <tr>
                                <td>@Html.LabelFor(model => model.categoryId)</td>
                                <td>@*@Html.EditorFor(model => model.categoryId)*@
                                    @Html.DropDownList("CategoryId", "Chọn loại sản phẩm")
                                    @Html.ValidationMessageFor(model => model.categoryId)</td>
                            </tr>
                            <tr>
                                <td>@Html.LabelFor(model => model.visible)</td>
                                <td>@Html.EditorFor(model => model.visible)
                                    @Html.ValidationMessageFor(model => model.visible)</td>
                            </tr>
                            <tr>
                                <td>@Html.LabelFor(model => model.regionId)</td>
                                <td>@*@Html.EditorFor(model => model.regionId)*@
                                    @Html.DropDownList("RegionId", "Chọn xuất xứ")
                                    @Html.ValidationMessageFor(model => model.regionId)</td>
                            </tr>
                            <tr>
                                <td></td>
                                <td>
                                    <input type="hidden" name="ReturnURL" value="@ViewBag.ReturnURL" />
                                    <input type="submit" value="Save" />
                                </td>
                            </tr>
                        </table>
                    </fieldset>
                }
    </div>
    <div class="boxCreateRight"></div>
</div>
<div class="linkCommand">
@if (ViewBag.ReturnURL == null)
{
    @Html.ActionLink("Trở về", "productList")
}
else
{
    <a href="@ViewBag.ReturnURL">Trở về</a>
}
</div>

<script type="text/javascript">

    $(document).ready(function (e) {
        var validate = new Validate();
        validate.ganLabel("spanDeleteOldImage", "DeleteOldImage");
    });
</script>

